<!--/*验证码的session开始，如果不放在前面，有的服务器会出现警告*/-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title><?php include 'module/title.php'; ?></title>
    <link rel="Shortcut Icon" href="asset/logoicon.ico">
    <script type="text/javascript" src="asset/js/viewport.js"></script>
    <link rel="stylesheet" type="text/css" href="asset/css/style.css"/>
</head>



<body class="login_check">

<div class="container">
系统载入中，请稍等...
</div>



    <?php
    //验证登陆信息
    session_start();


        //用接口形式，换取数据库资料，再补充connection

        include_once ("../config.php");
        //include_once ("../connection.php");


        //if($_POST['submit']){
        $username = $_REQUEST['username'];
        $domain   = $_REQUEST['domain'];
        $password = $_REQUEST['userpass'];
        $password = md5($password);


        //接口获取网站的登录信息。
        //账密正确，则返回数据库名称。
        //返回theme_floder


        //传递上面的username 和domain等资料
        $_post_data = array(
            'username' => $username,
            'domain'   => $domain,
            'password'   => $password,
        );
        $_post_data = http_build_query($_post_data);


        $_url       ="https://".$_REQUEST['domain']."/api/console/system/site_manage_info.php?".$_post_data;




        $ch = curl_init($_url);
        //curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        //补充ua
        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36');
        $response = curl_exec($ch);
        if ($response === false) {
            $errorCode = curl_errno($ch);  // 获取错误代码
            echo "Curl error code: $errorCode\n";
            echo "Curl error: " . curl_error($ch) . "\n";
        }
        curl_close($ch);
        $_sync_domain = $response;



exit;






    //预防有些connection没有设置大写小写两个前缀
    if(!isset($table_prefix))
    {
        $table_prefix=$table_Prefix;
    }

//    print_r2($_REQUEST);


        //先判断接收的用户名，是否含有特殊字符。有的话，直接返回登陆框。
        if (!preg_match("/^[0-9a-zA-Z]{3,12}$/", $username))
        {
            echo "<script language='javascript'>alert('用户名格式有误，请检查！');location='/gate/';</script> ";
        }

        else
        {

            echo "正在验证账号...<br/>";

            $_user=select_one_line_all_items($table_prefix."login_admin","name = '".$username."'");

            //print_r2($_user);


            if (!$_user)
            {
                //print_r2($_user);
                echo "<script >alert('用户名不存在!');location='/gate/';</script>";
            }

            elseif ($_user['admin_password'] != $userpass)
            {

                echo "<script >alert('密码错误！');location='/gate/';</script>";
            }


            elseif($_user)
            {
                //全部校验通过 数据存入session

                $_SESSION['username']   = $_user['name'];
                $_SESSION['admin_id']   = $_user['nid'];
                $_SESSION['admin_name'] = $_user['name'];
                $_SESSION['admin_term'] = $_user['admin_term'];

                $url="/controller/index.php";
                Header("Location: $url");
            }


        ;}




 ?>

</body>